import 'package:flutter/material.dart';
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:web_socket_channel/io.dart';
import './module/my_socket.dart';
// 页面
import './pages/user_chat.dart';
import './pages/home_page.dart';
void main() {
  runApp(MyApp());

  var channel = new IOWebSocketChannel.connect("ws://192.168.1.195:999/");
  MySocket.instance = MySocket(socket: channel,name1: '你好啊');
  MySocket().myWss().stream.listen(MySocket().lisenMsg);
  MySocket().onmsg('connection', (data) {
    print('收到消息${data}');
    MySocket().emits('re_connection', {
      'name': '控制端',
      'type': 'User'
    });
  });
  MySocket().onmsg('hello', (data) {
    print(data);
  });

  
  if (Platform.isAndroid) {
    SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
      statusBarColor: Colors.transparent
    );
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
  }
}



class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title:'DEMO',
      debugShowCheckedModeBanner: false,
      home:MyHome(),
      routes: {
        '': (context) => HomePages(),
        '/chat': (context) => UserChat(),
      },
    );
  }
}

class MyHome extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    // MySocket.instance =  MySocket(width: 750, height: 1500)..init(context);
    ScreenUtil.instance = ScreenUtil(width: 750, height: 1500)..init(context);
    return HomePages(); 
  }
}